package zhupf.test.threadTest;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;


public class Ticket {
    private int number = 30;
    Lock lock = new ReentrantLock();

    public void salve(){
        lock.lock();
        try {
            if (number>0)
            System.out.println(Thread.currentThread().getName()+":售卖第"+number--+"张票，还剩"+number+"张票");
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            lock.unlock();
        }
    }
}
